// -----------------------------------------------------------------------
//  <copyright file="ISpecificationEvaluator.cs" company="LiuliuSoft">
//      Copyright (c) 2022-2022 DaprPlus. All rights reserved.
//  </copyright>
//  <site>https://www.dapr.plus</site>
//  <last-editor>郭明锋</last-editor>
//  <last-date>2022-11-01 19:13</last-date>
// -----------------------------------------------------------------------

using DaprPlus.Domain.Entity;


namespace DaprPlus.Specifications;

/// <summary>
/// 定义查询规约执行器
/// </summary>
public interface ISpecificationEvaluator
{
    /// <summary>
    /// 执行规约查询
    /// </summary>
    /// <typeparam name="T">项类型</typeparam>
    /// <param name="source">数据源</param>
    /// <param name="specification">查询规约</param>
    /// <returns></returns>
    IQueryable<T> Query<T>(IQueryable<T> source, ISpecification<T> specification) where T  : class, IEntity;

    /// <summary>
    /// 执行规约查询，并返回总记录数
    /// </summary>
    /// <typeparam name="T">项类型</typeparam>
    /// <param name="source">数据源</param>
    /// <param name="specification">查询规约</param>
    /// <param name="token"></param>
    /// <returns></returns>
    Task<(IQueryable<T> query, int total)> QueryAsync<T>(IQueryable<T> source, ISpecification<T> specification, CancellationToken token = default) where T : class, IEntity;
}
